package CompleteFutureDemo;

import common.CalcTask;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;

public class ForkJoinPoolTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ForkJoinPool joinPool = new ForkJoinPool();
        CompletableFuture<Double> cf1 = CompletableFuture.supplyAsync(() -> new CalcTask().RunWithResult(),joinPool);
        CompletableFuture<Void> cf2 = CompletableFuture.runAsync(() -> new CalcTask().Run(),joinPool);
        System.out.println("主线程执行："+System.currentTimeMillis());
        System.out.println("执行结果："+cf1.get());
        System.out.println("执行结果："+cf2.get());
        joinPool.shutdown();
        System.out.println("主线程结束："+System.currentTimeMillis());

    }
}
